public class Test {

    public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
        ListNode list = new ListNode(0);

        ListNode cur = list;

        while(list1 != null && list2 != null){
            if(list1.val > list2.val){
                cur.next = list2;
                list2 = list2.next;
            }else{
                cur.next = list1;
                list1 = list1.next;
            }

            cur = cur.next;
        }

        cur.next = list1 == null ? list2 : list1 ;
        return list.next;


    }


    public ListNode mergeTwoLists2(ListNode list1, ListNode list2) {
        ListNode list = new ListNode();

        if(list1 == null && list2 == null){
            return null;
        }

        if(list1 == null ){
            return list2;
        }

        if(list2 == null ){
            return list1;
        }

        if(list1.val > list2.val){
            list2.next = mergeTwoLists(list2.next , list1);
            return list2;
        }else {
            list1.next = mergeTwoLists(list1.next , list2);
            return list1;
        }
    }
}
